import { Controller, Get, Post, Res, SetMetadata, UseGuards, Request } from '@nestjs/common';
import { LocalAuthGuard } from './modules/auth/LocalAuthGuard';
import { AuthService } from './modules/auth/auth.service';
import { JwtAuthGuard } from './modules/auth/jwt-auth.guard';

@Controller()
export class AppController {
  constructor(private authService: AuthService) {
  }

  @Get('login')
  @SetMetadata('roles', ['admin'])
  getHello(@Res() res) {
    res.cookie('c-name', 'zhangsan', { maxAge: 900000, httpOnly: true });
    res.status(200).send('login success');
  }

  // @UseGuards(AuthGuard('local'))
  @UseGuards(LocalAuthGuard)
  @Post('auth/login')
  async login(@Request() req) {
    // return req.user;
    return this.authService.login(req.user);
  }

  @UseGuards(JwtAuthGuard)
  @Get('profile')
  getProfile(@Request() req) {
    return req.user;
  }


}
